<?php
namespace app\asmpasync\service;
use Client\Reboot;
use Client\Restart;


/**
 * @name: 客户端接口
 * @Param: 
 * @Description: 
 * @Author: foo
 * @Date: 2019-12-11 11:23:33
 */
class Client
{
    public $classDescription = '客户端操作';//模块描述
    public $actionDescription = '';//操作描述
    /**
     * @name:客户端硬件信息
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:25:57
     */
    function MachineInfo ()
    {
        $this->actionDescription = '硬件信息上传';
        $MachineInfo = new \Client\MachineInfo();
        
        return $MachineInfo;
    }

    /**
     * @name:客户端硬件信息
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:25:57
     */
    private function Module ($name, $enable)
    {
        $Module = new \Client\Module();
        $Module->setName($name);
        $Module->setEnable($enable ? true : false);

        return $Module;
    }

    /**
     * @name: 模块列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:26:30
     */
    function Modules ($host_id)
    {
        $this->actionDescription = '模块信息';
        $moduleConfig = db('HostModuleRelation')->where('host_id', $host_id)->find();
        $moduleConfig = array_slice($moduleConfig, 3);
        $Modules = new \Client\Modules();
        foreach ($moduleConfig as $name => $enable)
        {
            $moduleList[] = $this->Module($name, $enable);
        }

        $Modules->setList($moduleList);

        return $Modules;
    }

    /**
     * @name: 更新
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:26:55
     */
    function Update ()
    {
        $this->actionDescription = '客户端更新';
        $Update = new \Client\Update();
        $Update->setStart(true);
        return $Update;
    }

    /**
     * @name: 卸载
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:27:18
     */
    function Uninsatll ()
    {
        $this->actionDescription = '客户端卸载';
        $Uninstall = new \Client\Uninsatll();
        $Uninstall->setEnable(true);

       return $Uninstall;
    }

    /**
     * @name: 端口列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:28:19
     */
    function Ports ()
    {
        $this->actionDescription = '端口列表上传';
        $Ports = new \Client\Ports();
        $Ports->setPorts([]);

        return $Ports;
    }

    /**
     * @name: 重启软件
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-11 11:28:19
     */
    function Restart ()
    {
        $this->actionDescription = '重启软件';


        $Restart = new Restart();

        $Restart->setEnable(true);

        return $Restart;
    }

    /**
     * @name 重启操作系统
     * @author wx
     * @date 2020/6/22 10:10
     */
    function Reboot()
    {
        $this->actionDescription = '重启软件';
        $Reboot = new Reboot();
        $Reboot->setEnable(true);

        return $Reboot;
    }
}
